package postpic.domain;

import org.json.JSONObject;

import postpic.json.JSONSerializable;

public class User implements JSONSerializable {
	
	private Integer userId;
	private String nameFirst;
	private String nameLast;
	private String email;
	
	public Integer getUserId() {
		return userId;
	}
	
	public void setUserId(final Integer userId) {
		this.userId = userId;
	}
	
	public String getNameFirst() {
		return nameFirst;
	}
	
	public void setNameFirst(final String nameFirst) {
		this.nameFirst = nameFirst;
	}
	
	public String getNameLast() {
		return nameLast;
	}
	
	public void setNameLast(final String nameLast) {
		this.nameLast = nameLast;
	}
	
	public String getEmail() {
		return email;
	}
	
	public void setEmail(final String email) {
		this.email = email;
	}
	
	@Override
	public String toString() {
		return getJSON().toString();
	}
	
	@Override
	public JSONObject getJSON() {
		final JSONObject json = new JSONObject();
		json.put("userId", userId);
		json.put("nameFirst", nameFirst);
		json.put("nameLast", nameLast);
		json.put("email", email);
		return json;
	}
	
	@Override
	public void populateFromJSON(JSONObject json) {
		try {
			setUserId(json.getInt("userId"));
		} catch (NumberFormatException nfe) {
			System.out.println(nfe.getStackTrace());
		}
		setNameFirst(json.getString("nameFirst"));
		setNameLast(json.getString("nameLast"));
		setEmail(json.getString("email"));
	}
	
}
